@isTest
private class HelloWorldTestClass {

	//TODO: Create a test method
	static testMethod void unitTest1 () {
		User adminuser = [SELECT id from User where alias = 'AUser'];
		// TODO: Instantiate a positions list
		List <Position__c> positions = new List<Position__c> ();

		// TODO: Create a for loop to create 20 new positions with unique names and descrptions
		for (Integer i = 0; i < 20; i++) {
			Position__c testPos= new Position__c();
			testPos.name = 'Name ' + i;
			testPos.job_description__c = 'Description ' + i;
			testPos.hiring_manager__c = adminuser.id;
			positions.add(testPos);
		}
		//TODO: Wrap the following section in a try block
		try {
			Test.startTest();
			System.debug('Attempting to insert positions');
			//TODO: Insert Positions
			insert positions;
			System.debug('Insert complete');

			// refresh the Position list to include the Hello__c field after the insert
			
			//TODO: Create a position map to hold position IDs
			
			//LMM: Note, constructor can take list, and parases out ids for keys
			//Map <ID,Position__c> positionIDs = new Map <ID,Position__c>(positions);
			//Set<Id> posIds = positionIDs.keySet();

			//TODO: Write a SOQL statement to retrieve id, name and Hello_c into positions based on the IDs in the position map
			//LMM: Note, when provided with list for "in" argument, will use ids for matching
			List<Position__c> dbpositions = [select id, name, hello__c from position__c where id in :positions];

			//TODO: Write a loop to iterate through the positions object
			for (Position__c curPos: dbpositions) {
				System.assertNotEquals(curPos.id, null);
				System.assertEquals(curPos.hello__c, 'World');
				System.debug('Position id=' + curPos.id +'; name=' + curPos.name + '; hello__c=' + curPos.hello__c);
			}
			
			//TODO: Inside the loop: ensure position id is not null and hello field contains 'World' 
			//TODO: Inside the loop: write position id, name and Hello__c value to the debug log 
		} catch (DMLException e) {	

			//TODO: Wrap the following section in a catch block
			System.debug('We caught a DML exception: ' + e.getDmlMessage(0));	
		}
		Test.stopTest();
	}
	
}